import { http } from "@/utils/http";

export type commonResult<T> = {
  code: number;
  msg: string;
  result: T;
};

export type infoType = {
  id?: number,
  projectId?: number,
  topoName?: string,
  topoData?: object,
  updatedBy?: number,
  updatedAt?: string,
  remark?: string,
}
export type infoTypeList = {
  data: infoType[];
  total: number;
};

const List = '/business/topo/v2/topo/page';
const Url = '/business/topo/v2/topo';
export const getList = (params?: object) => {
  return http.request<commonResult<infoTypeList>>("get", List, {
    params
  });
};
export const getInfo = (params?: object) => {
  return http.request<commonResult<{ topoInfo: infoType }>>("get", Url, {
    params
  });
};
export const addInfo = (data?: object) => {
  return http.request<commonResult<any>>("post", Url, {
    data
  });
};
export const editInfo = (data?: object) => {
  return http.request<commonResult<any>>("put", Url, {
    data
  });
};
export const deleteInfo = (data?: object) => {
  return http.request<commonResult<any>>("delete", Url, {
    data
  });
};


export type topoInfo = {
  id: number;
  projectId: number;
  topoName: string;
  topoData?: any;
  updatedBy: number;
  updatedByName: string;
  updatedAt: string;
};

export type getTopoPageResult = {
  data: topoInfo[];
  total: number;
};
export type getTopoResult = {
  topoInfo: topoInfo;
};


const topoPage = "/business/topo/v2/topo/page";
const topo = "/business/topo/v2/topo";
const topoData = "/business/topo/v2/topo/topo-data";

export const getTopoPage = (params?: object) => {
  return http.request<commonResult<getTopoPageResult>>("get", topoPage, {
    params
  });
};
export const addTopo = (data?: object) => {
  return http.request<commonResult<{}>>("post", topo, {
    data
  });
};
export const editTopo = (data?: object) => {
  return http.request<commonResult<{}>>("put", topo, {
    data
  });
};
export const deleteTopo = (data?: object) => {
  return http.request<commonResult<{}>>("delete", topo, {
    data
  });
};
export const getTopo = (params?: object) => {
  return http.request<commonResult<getTopoResult>>("get", topo, {
    params
  });
};
export const saveTopoData = (data?: object) => {
  return http.request<commonResult<{}>>("put", topoData, {
    data
  });
};

export type graphInfo = {
  id: number;
  groupId: number;
  graphName: string;
  graphImage: string;
  graphData: {
    name: string;
    icon: string;
    pen: {
      name: string;
      text?: string;
      width: number;
      height: number;
      image: string;
      imageRatio: boolean;
    };
  };
};

export type getGraphListResult = {
  data: graphInfo[];
};

/** 2.2.1 素材列表 */
const graphList = "/business/topo/v2/graph/list";
/**
 *  添加素材
 *  编辑素材
 *  删除素材
 */
const graph = "/business/topo/v2/graph";

export const getGraphList = (params?: object) => {
  return http.request<commonResult<getGraphListResult>>("get", graphList, {
    params
  });
};
export const addGraph = (data?: object) => {
  return http.request<commonResult<{}>>("post", graph, {
    data
  });
};
export const editGraph = (data?: object) => {
  return http.request<commonResult<{}>>("put", graph, {
    data
  });
};
export const deleteGraph = (data?: object) => {
  return http.request<commonResult<{}>>("delete", graph, {
    data
  });
};

export type graphGroupInfo = {
  id: number;
  groupName: number;
};

export type getGraphGroupListResult = {
  data: graphGroupInfo[];
};

/** 2.2.8 分组列表 */
const graphGroupList = "/business/topo/v2/graph-group/list";
/**
 *  添加分组
 *  修改分组
 *  删除分组
 */
const graphGroup = "/business/topo/v2/graph-group";

export const getGraphGroupList = (params?: object) => {
  return http.request<commonResult<getGraphGroupListResult>>(
    "get",
    graphGroupList,
    {
      params
    }
  );
};
export const addGraphGroup = (data?: object) => {
  return http.request<commonResult<{}>>("post", graphGroup, {
    data
  });
};
export const editGraphGroup = (data?: object) => {
  return http.request<commonResult<{}>>("put", graphGroup, {
    data
  });
};
export const deleteGraphGroup = (data?: object) => {
  return http.request<commonResult<{}>>("delete", graphGroup, {
    data
  });
};
